package com.zhang.heap;

import java.util.Comparator;

/**
 * @author 张吉鑫
 * @Description 堆的抽象类
 * @date 2021/4/7 14:38
 */
public abstract class AbstractHeap<E> implements Heap<E>{
    protected int size;
    protected Comparator comparator;
    public AbstractHeap() {
        this(null);
    }

    public AbstractHeap(Comparator comparator) {
        this.comparator = comparator;
    }

    @Override
    public int size() {
        return size;
    }

    @Override
    public boolean isEmpty() {
        return size == 0;
    }

    protected int compare(E e1,E e2){
        return comparator != null ? comparator.compare(e1,e2) : ((Comparable) e1).compareTo(e2);
    }

}
